//
//  TSCollectionViewDataSource.m
//  iOS_Store_V2
//
//  Created by Gary on 18/04/2017.
//  Copyright © 2017 czy. All rights reserved.
//

#import "TSCollectionViewDataSource.h"
#import <MJRefresh/MJRefresh.h>

@implementation TSCollectionViewDataSource


- (void)addPullRefresh {
    __weak __typeof(self) weakSelf = self;
    if (self.collectionView) {
        MJRefreshHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf reloadCollectionViewData:YES];
        }];
        self.collectionView.mj_header = header;
    }else if (self.asCollectionView) {
        MJRefreshHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf reloadCollectionViewData:YES];
        }];
        self.asCollectionView.view.mj_header = header;
    }
}

- (void)startPullRefresh {
    [super startPullRefresh];
}

- (void)stopPullRefresh {
    NSLog(@"start stopPullRefresh");
    if (self.collectionView) {
        [self.collectionView.mj_header endRefreshing];
    }else if (self.asCollectionView) {
        [self.asCollectionView.view.mj_header endRefreshing];
    }
}

- (void)addLoadingMoreView {
    __weak __typeof(self) weakSelf = self;
    self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [weakSelf loadMore];
        
    }];
    self.collectionView.mj_footer.hidden = YES;
    
}

- (void)setFooterViewState {
    if (self.currentPage < self.totalPage) {
        self.collectionView.mj_footer.hidden = NO;
    }else {
        self.collectionView.mj_footer.hidden = YES;
    }
}

- (void)stopLoadMore {
    [self.collectionView.mj_footer endRefreshing];
}

@end
